//
//  SXTBaseViewController.m
//  SXT
//
//  Created by 赵金鹏 on 16/8/16.
//  Copyright © 2016年 赵金鹏. All rights reserved.
//

#import "SXTBaseViewController.h"
#import "SXTAFNetworkingClient.h"
#import <SVProgressHUD.h>
#import "UIView+Toast.h"
@interface SXTBaseViewController ()

@end

@implementation SXTBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)POSTRequestURL:(NSString *)url param:(NSDictionary *)param isSuccess:(requestSuccessBlock)returnSuccess isError:(requestErrorBlock)returnError{
    
    [SVProgressHUD show];
    [SXTAFNetworkingClient POSTRequest:url
                                 param:param
                             isSuccess:^(id responseObject) {
                                 [SVProgressHUD dismiss];
                                 if (returnSuccess) {
                                     returnSuccess(responseObject);
                                 }
                            } isError:^(NSError *error) {
                                [SVProgressHUD dismiss];
                                [self showTostInView:@"请检查网络设置"];
                                if (returnError) {
                                    returnError(error);
                                }
                            }];
}

- (void)GETRequestURL:(NSString *)url param:(NSDictionary *)param isSuccess:(requestSuccessBlock)returnSuccess isError:(requestErrorBlock)returnError{
    [SVProgressHUD show];
    [SXTAFNetworkingClient GETRequest:url
                                 param:param
                             isSuccess:^(id responseObject) {
                                 [SVProgressHUD dismiss];
                                 if (returnSuccess) {
                                     returnSuccess(responseObject);
                                 }
                             } isError:^(NSError *error) {
                                 [SVProgressHUD dismiss];
                                 [self showTostInView:@"请检查网络设置"];
                                 if (returnError) {
                                     returnError(error);
                                 }
                             }];
}

- (void)showTostInView:(NSString *)tost{
    [self.view makeToast:tost duration:1.5 position:@"center"];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
